package B;

import java.util.Arrays;

class Solution {
    public static void main(String[] args) {
        int[] arr={-2,1,-3,4,-1,2,1,-5,4};
        System.out.println(new Solution().maxSubArray(arr));
    }
    public int maxSubArray(int[] nums) {
        int max=nums[0];
        for(int i=1;i<nums.length;i++){
            int temp=Math.max(nums[i-1],nums[i]);
            nums[i]=Math.max(nums[i-1]+nums[i],temp);
            max=Math.max(max,nums[i]);
        }
        System.out.println(Arrays.toString(nums));
        return nums[nums.length-1];
    }
}